import { compact, get } from 'lodash-es'
import { State } from '../state/types'

export class Hotel {
  id?: string
  code?: Nullable<string>
  name?: Nullable<string>
  begin_date?: string | Date
  end_date?: string | Date
  state_id?: string
  state?: State
  city?: Nullable<string>
  address?: Nullable<string>
  group?: Nullable<string>
  owner?: Nullable<string>
  star?: string
  rooms?: number
  contact_name?: Nullable<string>
  contact_phone?: Nullable<string>
  reference?: Nullable<string>
  appid?: Nullable<string>
  appsecret?: Nullable<string>
  template_id?: Nullable<string>
  display_name?: Nullable<string>
  image1?: Nullable<string>
  image2?: Nullable<string>
  image3?: Nullable<string>
  image4?: Nullable<string>
  created_id?: string
  updated_id?: string
  created_at?: string
  updated_at?: string
  version?: Nullable<number>;
  [key: string]: any

  constructor(data?: Hotel) {
    this.init(data)
  }
}

Hotel.prototype.full_address = function full_address(): string {
  return compact([get(this.state, 'name'), this.city, this.address]).join(' / ')
}

Hotel.prototype.init = function init(data?: Hotel) {
  this.id = get(data, 'id')
  this.code = get(data, 'code', '')
  this.name = get(data, 'name', '')
  this.begin_date = get(data, 'begin_date')
  this.end_date = get(data, 'end_date')
  this.state_id = get(data, 'state_id')
  this.state = get(data, 'state')
  this.city = get(data, 'city', '')
  this.address = get(data, 'address', '')
  this.group = get(data, 'group', '')
  this.owner = get(data, 'owner', '')
  this.star = get(data, 'star', '')
  this.rooms = get(data, 'rooms', 0) as number
  this.contact_name = get(data, 'contact_name', '')
  this.contact_phone = get(data, 'contact_phone', '')
  this.reference = get(data, 'reference', '')
  this.appid = get(data, 'appid', '')
  this.appsecret = get(data, 'appsecret', '')
  this.template_id = get(data, 'template_id', '')
  this.display_name = get(data, 'display_name', '')
  this.image1 = get(data, 'image1', '')
  this.image2 = get(data, 'image2', '')
  this.image3 = get(data, 'image3', '')
  this.image4 = get(data, 'image4', '')
  this.created_id = get(data, 'created_id')
  this.updated_id = get(data, 'updated_id')
  this.created_at = get(data, 'created_at')
  this.updated_at = get(data, 'updated_id')
  this.version = get(data, 'version')
}
